/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufrgs.rescue.util;

import br.ufrgs.rescue.model.BuildingOnFire;
import java.util.Comparator;

/**
 *
 * @author rick
 */
public class BuildingOnFireComparator implements Comparator {

    @Override
    public int compare(Object b1, Object b2) throws ClassCastException {
        if (!(b1 instanceof BuildingOnFire) || !(b2 instanceof BuildingOnFire)) {
            throw new ClassCastException("Tipagem dos objetos inválida");
        }

        BuildingOnFire build1 = (BuildingOnFire) b1;
        BuildingOnFire build2 = (BuildingOnFire) b2;

//        if (build1.getCivilians() < build2.getCivilians()) {
        if (build1.getTotalArea() < build2.getTotalArea()) {
            return 1;
        } else {
            if (build1.getTotalArea() > build2.getTotalArea()) {
                return -1;
            } else if (build1.getTotalArea() == build2.getTotalArea()) {
                if (build1.getWater() > build2.getWater()) {
                    return 1;
                } else if (build1.getWater() < build2.getWater()) {
                    return -1;
                } else if (build1.getWater() == build2.getWater()) {
                    return 0;
                }
            }
        }
        return 0;
    }
}
